import {M, CM, MM} from "../enum/DimensionUnits";

/**
 * 单位换算
 * @param value     待转化的值
 * @param fromUnit  原单位
 * @param toUnit    转换的单位
 * @return {*}      转换后的值
 */
export const convertUnit = (value, fromUnit, toUnit)=>{
  //判断数组可能为空的情况
  if(!value) return null;
  //判断待转换的单位
  switch(fromUnit) {
    case M:
      return toUnit === M?value:toUnit === CM?value*100:toUnit === MM?value*1000:value;
    case CM:
      return toUnit === M?value/100:toUnit === CM?value:toUnit === MM?value*10:value;
    case MM:
      return toUnit === M?value/1000:toUnit === CM?value/10:toUnit === MM?value:value;
    default:
      return value;
  }
};



// WEBPACK FOOTER //
// ./src/assets/js/utils/DiseaseUtils.js